package weixinkeji.dev.power.user.h;

import MyUI.ligerUI.bean.LigerUIPage;
import MyUI.ligerUI.service.LigeruiService;
import sys.wx.ann.hm.H;
import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.GL;
import sys.wx.c.ATR;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.SQL.mysql.common.TJF;
import sys.wx.m.db.SQL.mysql.common.orderby.TCOrderBy;
import sys.wx.m.db.SQL.mysql.common.where.WhereConfig;
import sys.wx.m.db.dao.mysql.Dao;
import sys.wx.util.ToolService;
import weixinkeji.dev.power.user.bean.SysUser;
import weixinkeji.dev.power.user.h.vo.SysUserVO;

/**
 *
 * @author IK
 */
@GL
@H("weixinkeji/dev/power/user/sysuser/manager")
public class SysUserSManager {

    ATR a;                  //ATR是必须要的。它封装了web请求的相关信息

    public SysUserSManager(ATR obj) {     //这个有参构造函数，也是必须的。它进行附值
        this.a = obj;
    }

    @M("/sPage")
    public String a1() {
        LigerUIPage page = LigeruiService.getPage(a.request);
        SysUserVO vo = CV.getObjectByFields(SysUserVO.class, a.request);
        boolean noTJ = null == vo;
        String tj = getTJ(vo);
        a.printOne(LigeruiService.getGRID_1_2(Dao.selectVastOrderBy(SysUser.class, noTJ ? null : tj, page.page, page.pagesize,
                ToolService.IsNullOREmpty(page.sortname) ? null : TCOrderBy.getOrderBy(SysUser.class, page.sortname, page.sortorder)), Dao.selectCount(SysUser.class, tj), 1)
        );
        return null;
    }

    private String getTJ(SysUserVO vo) {
        WhereConfig config = new WhereConfig(SysUser.class, "");
        Where wh = TJF.getWhere(config);

        wh.put(Where.TJ_IGNORE_EMPTY_NULL, "", "sort", "!=", 0);
        wh.put(Where.TJ_IGNORE_EMPTY_NULL, Where.AND, "user_account", "=", vo.account);
        wh.put(Where.TJ_IGNORE_EMPTY_NULL, Where.AND, "user_name", "=", vo.name);
        wh.put(Where.TJ_IGNORE_EMPTY_NULL, Where.AND, "style", "=", vo.account);
        wh.put(Where.TJ_IGNORE_EMPTY_NULL, Where.AND, "sort", "=", vo.account);
        return wh.getWhere();

//
//        TCWhere tj = TJF.getWhere(SysUser.class, null);
//        String sql;
////        if (!ToolService.IsNullOREmpty(vo.account)) {
////            tj.putAND("user_account", "=", vo.account);
////        }
////        if (!ToolService.IsNullOREmpty(vo.name)) {
////            tj.putAND("user_name", "=", vo.name);
////        }
//        if (!ToolService.IsNullOREmpty(vo.style)) {
//            tj.putAND("style", "=", vo.style);
//        }
//        if (!ToolService.IsNullOREmpty(vo.sort)) {
//            tj.putAND("sort", "=", vo.sort);
//        } else {
//            tj.putAND("sort", "!=", "0");
//        }
//        sql = tj.getWhere();
//        if (tj.getWhere().startsWith(TCWhere.AND)) {
//            return sql.substring(TCWhere.AND.length());
//        }
//        return sql;
    }
}
